package com.shuyun;

import sun.misc.Unsafe;

/**
 * @description:
 * @author: shuai.chen@shuyun.com
 * @date: 2023/1/16 6:00 PM
 */
public class UnsafeTest {

    int a = 0;
    int b = 1;

    Unsafe unsafe = Unsafe.getUnsafe();

    public static void main(String[] args) {

    }

    // CPU0
    void foo() {
        a = 1;
        unsafe.storeFence();
        b = 1;
    }

    // CPU1
    void bar() {
        while (b == 0) continue;
        unsafe.loadFence();
        assert(a == 1);
    }

}
